package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleService;
import com.heima.common.constants.message.HotArticleConstants;
import com.heima.model.article.pojo.ArticleVisitStreamMess;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * Created by ZYJ on 2021/6/10 15:34
 */
@Component
@Slf4j
public class ArticleIncrHandleListener {
    @Autowired
    ApArticleService articleService;

    @KafkaListener(topics = HotArticleConstants.HOTARTICLE_INCR_HANDLE_OUPUT_TOPIC)
    public void receiveMessage(String message){
        log.info("kafka监听触发  更新文章热度值 :{}", message);
        articleService.updateApArticle(JSON.parseObject(message, ArticleVisitStreamMess.class));
    }
}
